
# 字典的创建练习
def dict_demo():

    dict_1 = {'name':'zhangsan','age':18}
    dict_2 = dict(name='lisi',age=19)
    for key,value in dict_1.items():
        print(key,value)
    print(dict_2.values())
    # 删除字典中的元素
    del dict_1['name']
    # 键不存在时抛出异常
    try:
        print(dict_1['name'])
    except KeyError:
        print("key is not exist")
    print(dict_1.get('name'))

# 控制结构练习
def control_strcture():
    # 顺序结构
    for i in range(1,10):
        print(i)

    # 分支结构
    if 1 == 1:
        print("Yes")
    # 二分支结构
    if 1 == 1:
        print("Yes")
    else:
        print("No")

    # 多分支结构
    if 1 == 1:
        print("Yes")
    elif 2 == 2:
        print("No")
    else:
        print("Maybe")


    # 循环结构 while  ; for循环

    for i in "python":
        print(i)
    else:
        print('循环结束')

data ={'性别':'男','爱好':'读书'}
def people(name,number,**p):
    print('姓名：',name,'学号：',number,'其他：',p)


if __name__ == '__main__':
    s = [1,2,3,45]
    if 2 in s:
        print("Yes")

    # complex number复数的创建练习
    real_number_as_complex = complex(5)
    print(real_number_as_complex)
    print(real_number_as_complex.real)
    dict_demo()

    # 集合的创建
    set_1 = {'医生','护士', '病人'}
    set_2 = set([1,2,3,4,5])
    print(type(set_1))
    # 集合的访问遍历
    for item in set_1:
        print(item)

    try:
        print(set_1[0])
    except:
        print("集合没有索引")
    else:
        print("集合有索引")
    finally:
        print("集合的访问遍历结束")

    people('张三',123,**data)

    ## 匿名函数lambda
    # 匿名函数适合用于处理不再需要在其他位置复用代码的函数逻辑，
    # 可以省去函数的定义过程和函数的命名，使代码更加简洁，提高可读性。例如：
    f  = lambda x,y:x+y
    print(f(1,2))